package priv.hxm.clien;

import priv.mill.net.MessageContexts;
import priv.mill.net.MessageObj;
import priv.mill.net.MyHttp;
import priv.mill.net.UrlType;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

public class MyClientHandler extends ChannelHandlerAdapter {

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		// TODO 自动生成的方法存根
		
		cause.printStackTrace();
	}
	/**
	 * 服务器有消息返回的处理方法
	 */
	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		MessageObj peekMessage = MessageContexts.getInstance().pollMessage();
		MyHttp mHttp=(MyHttp) msg;
		UrlType type = mHttp.getType();
		/**
		 * 处理广播消息
		 */
		if(type.equals(UrlType.GUANG_BO)){
			
		}
		
		/**
		 * 处理正常消息
		 */
		if(peekMessage!=null && type.equals(UrlType.NALMORE)){
			peekMessage.handlerMessage((MyHttp)msg);
			//System.out.println(MessageContexts.flage);
			MessageContexts.flage=true;
		}
		//System.out.println(msg);
	}
	
}